package com.awakening.ChannelHandler;

import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.util.CharsetUtil;

import java.nio.charset.Charset;

/**
 * @Author:AwakeningCode
 * @Date: Created in 14:32 2018\3\6 0006
 */
public class Test {

    public static void main(String[] args) {

        /*ChannelPipeline pipeline = ...;
        FirstHandler firstHandler = new FirstHandler();
        //将该实例作为“handler1”添加到ChannelPipeline中
        pipeline.addLast("handler1",firstHandler);
        //将一个SecondHandler的实例作为“handler2”添加到ChannelPipeline的第一个槽中，这意味着它将被放置在已有的“handler1”之前
        pipeline.addLast("handler2",new SecondHandler());
        //将一个ThirdHandler的实例作为“handler3”添加到ChannelPipeline的最后一个槽中
        pipeline.addLast("handler3",new ThirdHandler());
        ...
        //通过名称移除“handler3”
        pipeline.remove("handler3");
        //通过引用移除FirstHandler
        pipeline.remove(firstHandler);
        //将SecondHandler（“handler2”）替换为FourthHandler:"handler4"
        pipeline.replace("handler2","handler4",new ForthHandler());*/


        /*ChannelHandlerContext ctx = ..;
        //获取到与ChannelHandlerContext相关联的Channel的引用
        Channel channel = ctx.channel();
        //通过Channel写入缓冲区
        channel.write(Unpooled.copiedBuffer("Netty in Action", CharsetUtil.UTF_8));*/

        /*ChannelHandlerContext ctx = ..;
        ChannelPipeline pipeline = ctx.pipeline();
        //通过ChannelPipeline写入缓冲区
        pipeline.write(Unpooled.copiedBuffer("Netty in Action",CharsetUtil.UTF_8));*/


       /* ChannelFuture future = channel.wirte(someMessage);
        future.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture channelFuture) throws Exception {
                if (!channelFuture.isSuccess()){
                    channelFuture.cause().printStackTrace();
                    channelFuture.channel().close();
                }
            }
        });*/

    }

}
